home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Graphics Programming (2nd Edition) / Visual Basic Graphics Programming 2nd Edition.iso / Src / Ch9 / SaverCvr.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1999-05-31  |  3.4 KB  |  110 lines

  1. VERSION 5.00
  2. Begin VB.Form frmCover 
  3.    BackColor       =   &H00000000&
  4.    BorderStyle     =   0  'None
  5.    ClientHeight    =   2910
  6.    ClientLeft      =   2010
  7.    ClientTop       =   2430
  8.    ClientWidth     =   3480
  9.    ControlBox      =   0   'False
  10.    FillStyle       =   0  'Solid
  11.    LinkTopic       =   "Form1"
  12.    MaxButton       =   0   'False
  13.    MinButton       =   0   'False
  14.    PaletteMode     =   1  'UseZOrder
  15.    ScaleHeight     =   194
  16.    ScaleMode       =   3  'Pixel
  17.    ScaleWidth      =   232
  18.    ShowInTaskbar   =   0   'False
  19.    WindowState     =   2  'Maximized
  20.    Begin VB.Timer tmrMoveBalls 
  21.       Interval        =   50
  22.       Left            =   1800
  23.       Top             =   960
  24.    End
  25. Attribute VB_Name = "frmCover"
  26. Attribute VB_GlobalNameSpace = False
  27. Attribute VB_Creatable = False
  28. Attribute VB_PredeclaredId = True
  29. Attribute VB_Exposed = False
  30. Option Explicit
  31. Private Sub Form_Click()
  32.     If RunMode = rmScreenSaver Then Unload Me
  33. End Sub
  34. Private Sub Form_DblClick()
  35.     If RunMode = rmScreenSaver Then Unload Me
  36. End Sub
  37. Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
  38.     If RunMode = rmScreenSaver Then Unload Me
  39. End Sub
  40. Private Sub Form_KeyPress(KeyAscii As Integer)
  41.     If RunMode = rmScreenSaver Then Unload Me
  42. End Sub
  43. Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  44.     If RunMode = rmScreenSaver Then Unload Me
  45. End Sub
  46. Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  47. Static x0 As Integer
  48. Static y0 As Integer
  49.     ' Do nothing except in screen saver mode.
  50.     If RunMode <> rmScreenSaver Then Exit Sub
  51.     ' Unload on large mouse movements.
  52.     If ((x0 = 0) And (y0 = 0)) Or _
  53.         ((Abs(x0 - X) < 5) And (Abs(y0 - Y) < 5)) _
  54.         Then
  55.             ' It's a small movement.
  56.             x0 = X
  57.             y0 = Y
  58.             Exit Sub
  59.     End If
  60.     Unload Me
  61. End Sub
  62. Private Sub Form_Resize()
  63.     ' Load configuration information.
  64.     LoadConfig
  65.     ' Initialize the balls.
  66.     InitializeBalls
  67. End Sub
  68. ' Redisplay the cursor if we hid it in Sub Main.
  69. Private Sub Form_Unload(Cancel As Integer)
  70.     If RunMode = rmScreenSaver Then ShowCursor True
  71. End Sub
  72. ' Move the balls.
  73. Private Sub tmrMoveBalls_Timer()
  74. Dim i As Integer
  75. Dim wid As Single
  76. Dim hgt As Single
  77.     ' Erase the balls.
  78.     For i = 1 To NumBalls
  79.         With Balls(i)
  80.             FillColor = BackColor
  81.             Circle (.BallX, .BallY), .BallR, BackColor
  82.         End With
  83.     Next i
  84.     ' Move and redraw the balls.
  85.     wid = ScaleWidth
  86.     hgt = ScaleHeight
  87.     For i = 1 To NumBalls
  88.         With Balls(i)
  89.             .BallX = .BallX + .BallVx
  90.             If .BallX < .BallR Then
  91.                 .BallX = 2 * .BallR - .BallX
  92.                 .BallVx = -.BallVx
  93.             ElseIf .BallX > wid - .BallR Then
  94.                 .BallX = 2 * (wid - .BallR) - .BallX
  95.                 .BallVx = -.BallVx
  96.             End If
  97.             .BallY = .BallY + .BallVy
  98.             If .BallY < .BallR Then
  99.                 .BallY = 2 * .BallR - .BallY
  100.                 .BallVy = -.BallVy
  101.             ElseIf .BallY > hgt - .BallR Then
  102.                 .BallY = 2 * (hgt - .BallR) - .BallY
  103.                 .BallVy = -.BallVy
  104.             End If
  105.             FillColor = .BallClr
  106.             Circle (.BallX, .BallY), .BallR, .BallClr
  107.         End With
  108.     Next i
  109. End Sub
  110.